package br.com.ss.bean;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.EJBException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import br.com.ss.entity.Cliente;
import br.com.ss.enumeration.EMensageError;
import br.com.ss.enumeration.parametros.EWindowParameter;
import br.com.ss.facade.ClienteFacade;
import br.com.ss.util.FacesUtil;


@ManagedBean(name = "clienteCRUDBean")
@RequestScoped
public class ClienteCRUDBean extends AbstractMenageBean {
	
	@EJB
    private ClienteFacade clienteFacade;

	private Cliente cliente;
	
 //############################################################################################################################3
	   
    @PostConstruct
    public void init() {
    	limpar();
    }
    
    private void limpar(){
    	cliente = new Cliente();
    }
    
    public void viewCreateCliente() {
    	
    	Map<EWindowParameter, Object> parametros = new HashMap<EWindowParameter, Object>();
    	parametros.put(EWindowParameter.RESIZABLE, true);
    	parametros.put(EWindowParameter.DRAGGABLE, true);
    	parametros.put(EWindowParameter.MODAL, false);
    	
    	viewWindowCustomized("criarCliente", parametros);

    }

    
    public void createCliente(){
        try {
            clienteFacade.save(this.cliente);
        } catch (EJBException e) {
           FacesUtil.criarMensagemErro(EMensageError.ERRO_AO_INCLUIR_, new Object[]{"DOG"});
        }     
        
        limpar();
    }


      
    //############################################################################################################################3
     
    public Cliente getCliente() {
    	return cliente;
    }
    
    public void setCliente(Cliente cliente) {
    	this.cliente = cliente;
    }
	    
   
}
